package xpn.platform.modules.persistence;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import xpn.platform.common.persistence.AbstractBaseEntity;
import xpn.platform.modules.sys.user.SysUser;

import javax.persistence.*;

/**
 * 带审计功能的实体类：创建者和修改者
 * 
 * @author bobatkm Oct 29, 2017
 *
 */
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@Getter
@Setter
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" }, ignoreUnknown = true)
public abstract class AbstractAuditorEntity extends AbstractBaseEntity {

	private static final long serialVersionUID = 3624753920343246476L;

	@CreatedBy
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(nullable = true)
	private SysUser createdBy;

	@LastModifiedBy
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(nullable = true)
	private SysUser modifiedBy;
	
}
